﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PrdTaskMasterForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.BasicDataManage.PrdTaskMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>生产计划</title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table>
            <tr>
                <td align="right">
                    开始日期：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="BizDateFrom" style="width: 150px;" class="mini-datepicker" format="yyyy-MM-dd" />
                </td>
                <td align="right">
                    至：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="BizDateEnd" style="width: 150px;" class="mini-datepicker" format="yyyy-MM-dd" />
                </td>
                <td align="right">
                    产品编号：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="PrdCode" class="mini-textbox" emptytext="请输入产品编号" style="width: 150px;"
                        onenter="onKeyEnter" />
                </td>
                <td style="width: 100px">
                    <a class="mini-button" iconcls="icon-search" onclick="search()">查 询</a>
                </td>
            </tr>
            <tr>
                <td align="right">
                    班次：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="ShiftID" class="mini-combobox" style="width: 150px;" textfield="ShiftName"
                        valuefield="ShiftID" shownullitem="true" allowinput="false" />
                </td>
                <td align="right">
                    产线：
                </td>
                <td style="width: 150px;" align="left">
                    <div id="LineID" name="LineID" class="mini-combobox" onvaluechanged="onLineIDChanged"
                        style="width: 150px;" popupwidth="400" textfield="LineName" valuefield="LineID"
                        url="../Service/BasicDataManageHandler.ashx?action=GetLineListByCombobox">
                        <div property="columns">
                            <div header="产线编号" field="LineCode" width="40%">
                            </div>
                            <div header="产线名称" field="LineName" width="60%">
                            </div>
                        </div>
                    </div>
                </td>
                <td align="right">
                    设备：
                </td>
                <td style="width: 150px;" align="left">
                    <div id="EqID" name="EqID" class="mini-combobox" style="width: 150px;" popupwidth="400"
                        textfield="EqName" valuefield="EqID">
                        <div property="columns">
                            <div header="设备编号" field="EqCode" width="40%">
                            </div>
                            <div header="设备名称" field="EqName" width="60%">
                            </div>
                        </div>
                    </div>
                </td>
                <td style="width: 100px">
                    <a class="mini-button" iconcls="icon-reset" onclick="reset()">重 置</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a> <a
                        class="mini-button" iconcls="icon-edit" onclick="edit()" plain="true">编辑</a>
                    <span class="separator"></span><a class="mini-button" id="import" iconcls="icon-import"
                        onclick="importPrdTask();" plain="true">导入</a> <a class="mini-button" href="../ExcleTemplate/生产计划模板.xls"
                            id="download" iconcls="icon-download" plain="true">Excel模板</a> <span class="separator">
                            </span><a class="mini-button" iconcls="icon-freeze" onclick="freeze()" plain="true">
                                禁用</a> <a class="mini-button" iconcls="icon-unfrozen" onclick="unfrozen()" plain="true">
                                    启用</a> <span class="separator"></span><a class="mini-button" onclick="close()" iconcls="icon-close"
                                        plain="true">关闭</a>
                </td>
            </tr>
        </table>
    </div>
    <!--撑满页面-->
    <div class="mini-fit">
        <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="TaskID"
            sizelist="[10,20,50,100]" pagesize="20" onrowdblclick="ondoubleclick()">
            <div property="columns">
                <div type="indexcolumn">
                </div>
                <div field="RecStatus" width="60" headeralign="center" allowsort="true" renderer="onRecStatusRenderer">
                    状态
                </div>
                <div field="LineCode" width="80" headeralign="center" allowsort="true">
                    产线编号
                </div>
                <div field="LineName" width="120" headeralign="center" allowsort="true">
                    产线名称
                </div>
                <div field="PrdCode" width="120" headeralign="center" allowsort="true">
                    产品编号
                </div>
                <div field="PrdName" width="180" headeralign="center" allowsort="true">
                    产品名称
                </div>
                <div field="BizDate" width="110" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd">
                    日期
                </div>
                <div field="ShiftName" width="80" headeralign="center" allowsort="true">
                    班次
                </div>
                <div field="EqCode" width="120" headeralign="center" allowsort="true">
                    设备编号
                </div>
                <div field="EqName" width="180" headeralign="center" allowsort="true">
                    设备名称
                </div>
                <div field="PlanQty" width="80" headeralign="center" allowsort="true">
                    计划数量
                </div>
                <div field="PlanStartTime" width="130" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd HH:mm:ss">
                    计划开始时间
                </div>
                <div field="PlanEndTime" width="130" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd HH:mm:ss">
                    计划结束时间
                </div>
                <div field="ProcessIdx" width="80" headeralign="center" allowsort="true">
                    生产序号
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    mini.parse();
    var now = new Date();
    var nowYear = now.getFullYear();
    var nowMonth = now.getMonth();
    var bizDateFrom = mini.get("BizDateFrom");
    bizDateFrom.setValue(new Date(nowYear, nowMonth, 1));
    var bizDateEnd = mini.get("BizDateEnd");
    bizDateEnd.setValue(new Date());
    var ShiftID = mini.get("ShiftID");
    var EqID = mini.get("EqID");
    var grid = mini.get("grid1");
    ShiftID.setUrl("../Service/BasicDataManageHandler.ashx?action=GetShiftListByCombobox");
    grid.setUrl("../service/BasicDataManageHandler.ashx?action=GetPrdTaskList");
    grid.load();
    function onLineIDChanged(e) {
        if (e.value) {
            EqID.setUrl("../Service/BasicDataManageHandler.ashx?action=GetEquipmentListByCombobox&LineID=" + e.value);
        }
    }
    function add() {
        mini.open({
            url: "BasicDataManage/PrdTaskInfoForm.aspx",
            title: "新增生产计划", width: 770, height: 495,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new" };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }
    function importPrdTask() {
        mini.open({
            url: "BasicDataManage/ImportPrdTaskForm.aspx",
            title: "生产计划导入", width: 408, height: 116,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "import" };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }

    function ondoubleclick() { edit(); }
    function edit() {
        var rows = grid.getSelected();
        if (rows) {
            mini.open({
                url: "BasicDataManage/EditPrdTaskInfoForm.aspx",
                title: "编辑生产计划", width: 455, height: 495,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", TaskID: rows.TaskID, FlowID: rows.FlowID };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
        else {
            mini.alert("请选中一条您需要编辑的记录!");
        }
    }

    function freeze() {
        var rows = grid.getSelected();
        if (rows) {
            if (rows.RecStatus == true) {
                mini.confirm("您确定禁用？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: "../service/PublicHandler.ashx?action=Freeze&table=UT_PrdTask&field=TaskID&value=" + rows.TaskID,
                                success: function (text) {
                                    grid.reload();
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert(jqXHR.responseText);
                                }
                            });
                        } else {
                            return false;
                        }
                    });
            }
            else {
                mini.alert(rows.PrdName + " 当前状态已经是：已禁用!");
            }

        } else {
            mini.alert("请选中一条您需要禁用的记录!");
        }
    }

    function unfrozen() {
        var rows = grid.getSelected();
        if (rows) {
            if (rows.RecStatus == false) {
                mini.confirm("您确定启用？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: "../service/PublicHandler.ashx?action=Unfrozen&table=UT_PrdTask&field=TaskID&value=" + rows.TaskID,
                                success: function (text) {
                                    grid.reload();
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert(jqXHR.responseText);
                                }
                            });
                        } else {
                            return false;
                        }
                    });
            }
            else {
                mini.alert(rows.PrdName + " 当前状态已经是：已启用!");
            }

        } else {
            mini.alert("请选中一条您需要启用的记录!");
        }
    }
    //回车键事件
    function onKeyEnter() {
        search();
    }
    function search() {
        var BizDateFrom = mini.get("BizDateFrom").getFormValue();
        var BizDateEnd = mini.get("BizDateEnd").getFormValue();
        var ShiftID = mini.get("ShiftID").getValue();
        var EqID = mini.get("EqID").getValue();
        var PrdCode = mini.get("PrdCode").getValue();
        var LineID = mini.get("LineID").getValue();
        grid.load({ BizDateFrom: BizDateFrom, BizDateEnd: BizDateEnd, ShiftID: ShiftID, EqID: EqID, PrdCode: PrdCode, LineID: LineID });
    }

    //回车键事件
    function onKeyEnter() {
        search();
    }

    function reset() {
        bizDateFrom.setValue(new Date(nowYear, nowMonth, 1));
        bizDateEnd.setValue(new Date());
        mini.get("ShiftID").setValue("");
        mini.get("EqID").setValue("");
        mini.get("PrdCode").setValue("");
        mini.get("LineID").setValue("");
    }

    function onRecStatusRenderer(e) {
        if (e.value == "0") { return "<span style=\"color: Red;font-weight:bold;\">已禁用</span>"; }
        else if (e.value == "1") { return "<span style=\"color: Green;font-weight:bold;\">已启用</span>"; }
        else { return ""; }
    }

    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
    function close() {
        CloseWindow("close");
    }
</script>
